<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>parse_pitcher_game_data (GamedayParser)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File lib/gameday_parser.rb, line 41</span>
        <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse_pitcher_game_data</span>(<span class="ruby-identifier">doc</span>, <span class="ruby-identifier">game</span>, <span class="ruby-identifier">logger</span>)
                <span class="ruby-identifier">player</span> = <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">root</span>
                <span class="ruby-identifier">gameday_id</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'id'</span>]
                <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">gameday_id</span>)
                        <span class="ruby-identifier">team_abbrev</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'team'</span>]
                        <span class="ruby-identifier">team</span> = <span class="ruby-constant">Team</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:first</span>, <span class="ruby-identifier">:conditions=</span><span class="ruby-operator">&gt;</span><span class="ruby-node">&quot;abbreviation='#{team_abbrev}'&quot;</span>)
                        <span class="ruby-identifier">old_player</span> = <span class="ruby-constant">Player</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:first</span>, <span class="ruby-identifier">:conditions=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">'gameday_id='</span><span class="ruby-operator">+</span><span class="ruby-identifier">gameday_id</span>)
                        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">old_player</span>
                                <span class="ruby-comment cmt"># update player     </span>
                                <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">first_name</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'first_name'</span>]
                                <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">last_name</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'last_name'</span>]
                                <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">position</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'pos'</span>]
                                <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">jersey_number</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'jersey_number'</span>].<span class="ruby-identifier">to_i</span>
                                <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">height</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'height'</span>]
                                <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">weight</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'weight'</span>].<span class="ruby-identifier">to_i</span>
                                <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">bats</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'bats'</span>]
                                <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">throws</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'throws'</span>]
                                <span class="ruby-comment cmt">#old_player.birthdate = player.attributes['dob']</span>
                                <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">team_id</span> = <span class="ruby-identifier">team</span>.<span class="ruby-identifier">id</span>
                                <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">save</span>
                        <span class="ruby-keyword kw">else</span>
                                <span class="ruby-comment cmt"># create player     </span>
                                <span class="ruby-constant">Player</span>.<span class="ruby-identifier">create</span>(<span class="ruby-identifier">:gameday_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">gameday_id</span>, 
                                                          <span class="ruby-identifier">:first_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'first_name'</span>], 
                                                          <span class="ruby-identifier">:last_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'last_name'</span>], 
                                                          <span class="ruby-identifier">:position</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'pos'</span>], 
                                                          <span class="ruby-identifier">:jersey_number</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'jersey_number'</span>].<span class="ruby-identifier">to_i</span>, 
                                                          <span class="ruby-identifier">:height</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'height'</span>], 
                                                          <span class="ruby-identifier">:weight</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'weight'</span>].<span class="ruby-identifier">to_i</span>, 
                                                          <span class="ruby-identifier">:bats</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'bats'</span>], 
                                                          <span class="ruby-identifier">:throws</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'throws'</span>],
                                                          <span class="ruby-comment cmt">#:birthdate =&gt; player.attributes['dob'], </span>
                                                          <span class="ruby-identifier">:team_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">team</span>.<span class="ruby-identifier">id</span>)
                        <span class="ruby-keyword kw">end</span>
                <span class="ruby-keyword kw">end</span>   
        <span class="ruby-keyword kw">end</span></pre>
</body>
</html>